package com.xique.park.bean.transform.web.garageLaneDev;

import com.alibaba.fastjson.JSON;
import com.xique.common.core.utils.DateUtils;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.park.bean.domain.ParkChargeRuleComm;
import com.xique.park.bean.request.web.chargeRule.AddChargeRuleRequest;
import com.xique.park.bean.request.web.chargeRule.EditChargeRuleRequest;

/**
 * 收费规则转化类
 */
public class ChargeRuleTransform {

    /**
     * 添加收费模板转化
     * @param request
     * @return
     */
    public static ParkChargeRuleComm transformAddChargeRuleRequestToRuleComm(AddChargeRuleRequest request) {
        ParkChargeRuleComm ruleComm = new ParkChargeRuleComm();
        ruleComm.setParkId(SecurityUtils.getParkId());
        ruleComm.setName(request.getRuleName());
        ruleComm.setTemplate(null != request.getTemplate() ? Integer.parseInt(request.getTemplate()) : null);
        ruleComm.setContent(JSON.toJSONString(request.getContent()));
        ruleComm.setUpdateUser(SecurityUtils.getUserId());
        ruleComm.setCreateUser(SecurityUtils.getUserId());
        ruleComm.setUpdateTime(DateUtils.getNowDate());
        ruleComm.setCreateTime(DateUtils.getNowDate());
        return ruleComm;
    }

    /**
     * 编辑收费模板转化
     * @param request
     * @return
     */
    public static ParkChargeRuleComm transformEditChargeRuleRequestToRuleComm(EditChargeRuleRequest request) {
        ParkChargeRuleComm ruleComm = new ParkChargeRuleComm();
        ruleComm.setId(request.getRuleId());
        ruleComm.setParkId(SecurityUtils.getParkId());
        ruleComm.setName(request.getRuleName());
        ruleComm.setTemplate(null != request.getTemplate() ? Integer.parseInt(request.getTemplate()) : null);
        ruleComm.setContent(JSON.toJSONString(request.getContent()));
        ruleComm.setUpdateUser(SecurityUtils.getUserId());
        ruleComm.setUpdateTime(DateUtils.getNowDate());
        return ruleComm;
    }
}
